package com.mingmen.supplier.activity;


import android.content.Intent;
import android.graphics.drawable.shapes.Shape;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.mingmen.supplier.R;
import com.mingmen.supplier.adapter.CanCelOrderAdapter;
import com.mingmen.supplier.adapter.CommodityAdapter;
import com.mingmen.supplier.adapter.MyCommentAdapter;
import com.mingmen.supplier.adapter.PhotoWaiAdapter;
import com.mingmen.supplier.defineview.PhotoDialog;
import com.mingmen.supplier.http.callback.StringCallback;
import com.mingmen.supplier.httpconfig.HttpResponse;
import com.mingmen.supplier.immersionbar.ImmersionBar;
import com.mingmen.supplier.model.CancelModel;
import com.mingmen.supplier.model.MySimpleData;
import com.mingmen.supplier.util.GsonUtil;
import com.mingmen.supplier.util.MyStringUtils;
import com.mingmen.supplier.util.ScalableCardHelper;
import com.mingmen.supplier.util.SharePreferenceUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;
import okhttp3.Response;

public class CanCelOrderDetailActivity extends AppCompatActivity implements CommodityAdapter.OnItemClickListener, ScalableCardHelper.OnPageChangeListener {

    //返回按钮
    @BindView(R.id.text_return)
    TextView textReturn;


    @BindView(R.id.layout_Distribution)
    LinearLayout layout_Distribution;
    List<String> reData = new ArrayList<>();
    MyCommentAdapter myCommentAdapter;
    private String img1 = "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3933355596,669391437&fm=26&gp=0.jpg";
    private String img2 = "http://img4.imgtn.bdimg.com/it/u=1445674920,12445384&fm=26&gp=0.jpg";
    private String img3 = "http://img4.imgtn.bdimg.com/it/u=482593725,2192787331&fm=26&gp=0.jpg";
    private String img4 = "http://img5.imgtn.bdimg.com/it/u=2306608262,3534874273&fm=26&gp=0.jpg";
    private String img5 = "http://img3.imgtn.bdimg.com/it/u=1827863856,2661023953&fm=26&gp=0.jpg";
    private String img6 = "http://img0.imgtn.bdimg.com/it/u=2775335106,966369936&fm=26&gp=0.jpg";
    private String img7 = "http://img4.imgtn.bdimg.com/it/u=1881496596,2607061598&fm=26&gp=0.jpg";
    private String img8 = "http://img2.imgtn.bdimg.com/it/u=3129434724,2523766044&fm=26&gp=0.jpg";
    private String img9 = "http://img0.imgtn.bdimg.com/it/u=1199886885,3035315889&fm=26&gp=0.jpg";

    private String img10 = "http://img3.imgtn.bdimg.com/it/u=2911588266,3715444639&fm=26&gp=0.jpg";
    private String img11 = "http://img2.imgtn.bdimg.com/it/u=1823088812,4234717774&fm=26&gp=0.jpg";
    private String img12 = "http://img0.imgtn.bdimg.com/it/u=1196506210,3510975282&fm=26&gp=0.jpg";
    private String img13 = "http://fms.news.cn/swf/2019_qmtt/10_8_2019_qm_z/images/5.jpg";

    private ArrayList<String> imageData = new ArrayList<>();
    private List<MySimpleData> datas = new ArrayList<>();
    private PhotoWaiAdapter adapter;
    RecyclerView recycle_comment;
    CanCelOrderAdapter canCelOrderAdapter;
    List<CancelModel.DataBean.CancelDetailBean> dataList = new ArrayList<>();
    String token;
    String partCancelFlag;
    String partArriveFlag;
    String partRefuseFlag;
    String billId;
    @BindView(R.id.total)
    TextView total;
    @BindView(R.id.applyMoney)
    TextView applyMoney;
    @BindView(R.id.text_billId)
    TextView text_billId;
    String myShipping = "";
    String shippingFee = "";
    @BindView(R.id.shipping)
    TextView shipping;
    @BindView(R.id.restaurantName)
    TextView restaurantName;
    @BindView(R.id.address)
    TextView address;
    @BindView(R.id.orderDate)
    TextView orderDate;
    @BindView(R.id.linear_return)
    LinearLayout linear_return;

    //                startActivity(new Intent(CanCelOrderDetailActivity.this, CanCelShoplActivity.class));
    @BindView(R.id.layout_shopDetail)
    LinearLayout layout_shopDetail;
    String send_shopStr = "";
    @BindView(R.id.layout_score)
    LinearLayout layout_score;
    String str_Score;
    String getStr_Score;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cancelorder);
        ButterKnife.bind(this);
        ImmersionBar.with(this)
                .statusBarDarkFont(true, 0.2f)
                .init();
        recycle_comment = (RecyclerView) findViewById(R.id.recycle_comment);

        token = (String) SharePreferenceUtil.get(this, "token", "");
        billId = getIntent().getStringExtra("billId");
        partCancelFlag = getIntent().getStringExtra("partCancelFlag");
        partArriveFlag = getIntent().getStringExtra("partArriveFlag");
        partRefuseFlag = getIntent().getStringExtra("partRefuseFlag");
        recycle_comment.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
        canCelOrderAdapter = new CanCelOrderAdapter(this, dataList);
        recycle_comment.setAdapter(canCelOrderAdapter);
//        myCommentAdapter = new MyCommentAdapter(this, reData);

        ScalableCardHelper cardHelper = new ScalableCardHelper(this);
        cardHelper.attachToRecyclerView(recycle_comment);


        HttpResponse.getCancelOrder(token, billId, new StringCallback(this) {
            @Override
            public void onSuccess(String s, Call call, Response response) {
                CancelModel cancelModel = new CancelModel();
                cancelModel = GsonUtil.GsonToBean(s, CancelModel.class);
                send_shopStr = s;
                dataList.addAll(cancelModel.getData().get(0).getCancelDetail());

                canCelOrderAdapter.setDataList(dataList);
                restaurantName.setText(cancelModel.getData().get(0).getRestaurantName());
                address.setText(cancelModel.getData().get(0).getAddress());
                orderDate.setText(cancelModel.getData().get(0).getLimitDate());
                total.setText(cancelModel.getData().get(0).getTotal());
                applyMoney.setText("(￥" + cancelModel.getData().get(0).getApplyMoney() + "+配送费: " + "￥" + cancelModel.getData().get(0).getShippingFee() + "元" + ")");
                text_billId.setText("订单编号: " + cancelModel.getData().get(0).getBillId());
                if (cancelModel.getData().get(0).getShipping().equals("0")) {
                    shipping.setText("线下自取");
                } else {
                    shipping.setText("商家配送");
                }
                myShipping = cancelModel.getData().get(0).getShipping();
                shippingFee = cancelModel.getData().get(0).getShippingFee();
                str_Score = MyStringUtils.beanToString(cancelModel.getData().get(0).getEvalList());
                getStr_Score = cancelModel.getData().get(0).getScore() + "";
            }
        });

        initData();
        initMyView();
        initListener();
        canCelOrderAdapter.setOnitemClickLintener(new CanCelOrderAdapter.OnitemClick() {
            @Override
            public void onItemClick(View view, int parentPosition, int position, List<String> mList, List<MySimpleData> datas, List<CancelModel.DataBean.CancelDetailBean> myList) {
                Intent intent = new Intent(CanCelOrderDetailActivity.this, AuditDetailActivity.class);

//                        CommodityShopManagerActivity
                intent.putExtra("commodityId", myList.get(position).getCommodityId() + "");
                startActivity(intent);

            }


        });
    }


    @OnClick({R.id.text_return, R.id.layout_Distribution, R.id.linear_return, R.id.layout_shopDetail, R.id.layout_score})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.linear_return:
            case R.id.text_return:
                finish();
                break;

            case R.id.layout_Distribution:
//                startActivity(new Intent(CanCelOrderDetailActivity.this, DistributionModeActivity.class));
                break;
            case R.id.layout_shopDetail:
//                startActivity(new Intent(CanCelOrderDetailActivity.this, CanCelShoplActivity.class));
                Intent intent = new Intent(CanCelOrderDetailActivity.this, CanCelShoplActivity.class);
                intent.putExtra("send_shopStr", send_shopStr);
                startActivity(intent);

                break;
            case R.id.layout_score:

                if (str_Score.length() < 5) {
                    Toast.makeText(this, "当前无评价", Toast.LENGTH_SHORT).show();
                } else {
                    intent = new Intent(CanCelOrderDetailActivity.this, PingScoreActivity.class);
                    intent.putExtra("str_Score", str_Score);
                    intent.putExtra("getStr_Score", getStr_Score);
                    startActivity(intent);

                }
                break;
        }
    }


    @Override
    public void onItemClickListener(View view, int pos, List<String> myLiveList) {

    }

    private void initMyView() {

    }

    public void initData() {
        MySimpleData data = new MySimpleData();
        data.setTitle("秒速5厘米");
        imageData.add(img1);
        imageData.add(img2);
        imageData.add(img3);
        imageData.add(img4);
        imageData.add(img5);
        imageData.add(img6);
        imageData.add(img7);
        imageData.add(img8);
        imageData.add(img9);
        data.setImgs(imageData);

        datas.add(0, data);

        MySimpleData data2 = new MySimpleData();
        data2.setTitle("EVA");
        ArrayList<String> childData = new ArrayList<>();
        childData.add(img10);
        childData.add(img11);
        childData.add(img12);
        childData.add(img13);
        data2.setImgs(childData);

        datas.add(1, data2);
    }


    private void initListener() {
      /*  adapter.setCallBack(new PhotoWaiAdapter.OnMyAdapterCallBack() {
            @Override
            public void onItemClick(int position, ArrayList<String> itemImgs) {
                Bundle bundle = new Bundle();
                ArrayList<String> data = new ArrayList<>();
                data.addAll(itemImgs);
                bundle.putInt("currentPostion", position);
                bundle.putStringArrayList("imageData", itemImgs);

                PhotoDialog photoDialog = new PhotoDialog();
                photoDialog.setArguments(bundle);
                photoDialog.show(getSupportFragmentManager(), "");
            }
        });*/
    }

    @Override
    public void onPageSelected(int position) {

    }
}




